const router = require('koa-router')()
const { register, login } = require('../controller/user')
const getUserInfo = require('../middwares/getUserInfo')

router.prefix('/users')

// 获取用户的信息，携带token 就行
router.get('/getUserInfo',getUserInfo,(ctx,next)=>{
  ctx.body = ctx.userInfo
})

router.post('/register',async(ctx,next)=>{
  const { userName,password } = ctx.request.body
  console.log('来注册了',userName, password)
  ctx.body = await register({ userName, password, gender: 1 })
})


router.post('/login',async (ctx,next)=>{
  const { userName,password } = ctx.request.body
  console.log('登录了',userName, password)

  ctx.body = await login(userName, password)
})

module.exports = router
